package io.geekidea.springbootplus.system.service.impl;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.geekidea.springbootplus.framework.common.service.impl.BaseServiceImpl;
import io.geekidea.springbootplus.framework.core.pagination.PageInfo;
import io.geekidea.springbootplus.framework.core.pagination.Paging;
import io.geekidea.springbootplus.system.entity.SysCategory;
import io.geekidea.springbootplus.system.entity.SysProduct;
import io.geekidea.springbootplus.system.mapper.SysCategoryMapper;
import io.geekidea.springbootplus.system.param.SysCategoryPageParam;
import io.geekidea.springbootplus.system.service.SysCategoryService;
import io.geekidea.springbootplus.system.vo.SysProductQueryVo;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.io.Serializable;

@Service
@Transactional(rollbackFor = Exception.class)
public class SysCategoryServiceImpl extends BaseServiceImpl<SysCategoryMapper, SysCategory> implements SysCategoryService {

    @Resource
    private SysCategoryMapper sysCategoryMapper;

    @Override
    public boolean saveCategory(SysCategory category) throws Exception {
        return super.save(category);
    }

    @Override
    public boolean updateCategory(SysCategory category) throws Exception {
        return super.updateById(category);
    }

    @Override
    public boolean deleteCategoryById(Integer id) throws Exception {
        return super.removeById(id);
    }

    @Override
    public SysCategory getCategoryById(Serializable id) throws Exception {
        return super.getById(id);
    }

    @Override
    public Paging<SysCategory> getCategoryPageList() throws Exception {
        Page<SysCategory> page = new PageInfo<>(null, OrderItem.desc(getLambdaColumn(SysCategory::getId)));
        IPage<SysCategory> iPage = sysCategoryMapper.getSysCategoryPageList(page);
        return new Paging(iPage);
    }

    @Override
    public Paging<SysCategory> getChildrenCategoryByParentId(Integer parentId) throws Exception {
        return null;
    }

    @Override
    public SysCategory findSysCategoryById(Integer id) {
        return sysCategoryMapper.findSysCategoryById(id);
    }

    @Override
    public Paging<SysCategory> getSysCategoryPageListByParam(SysCategoryPageParam sysCategoryPageParam) {
        Page<SysCategory> page = new PageInfo<>(sysCategoryPageParam, OrderItem.desc(getLambdaColumn(SysCategory::getId)));
        IPage<SysCategory> iPage = sysCategoryMapper.getSysCategoryPageListByParam(page, sysCategoryPageParam);
        return new Paging(iPage);
    }


}

